package com.demo.designpattern.observer;

/**
 * Created by hunter
 *
 * @Description 观察者模式
 */
public class MainTest {

    public static void main(String[] args) {

        // ~--------- 自主编写接口的方式 begin
        Subject teacher = new Teacher();

        Observer student = new Student("张三");
        Observer student1 = new Student("李四");
        Observer student2 = new Student("王五");

        teacher.addObserver(student);
        teacher.addObserver(student1);
        teacher.addObserver(student2);

        teacher.doSomeThings();
        // ~--------- 自主编写接口的方式 end

        System.out.println("~----------- 华丽的分割线");

        // ~--------- 使用内置接口的方式 begin
        DefaultTeacher defaultTeacher = new DefaultTeacher();

        DefaultStudent defaultStudent = new DefaultStudent("赵六");
        DefaultStudent defaultStudent2 = new DefaultStudent("朱七");

        defaultTeacher.addObserver(defaultStudent);
        defaultTeacher.addObserver(defaultStudent2);

        defaultTeacher.doSomeThing();
        // ~--------- 使用内置接口的方式 end
    }
}
